/*
	NOTE: This filemust ABSOLUTELY remain in the base plugins directory!!!!
	Removing this function from the base directory can cause plugins that load this one's registerTextMod to fail
*/

local textModifiers = {}

function registerTextMod(name, func)
	textModifiers[name] = func
end

local function chatIn(ply, text, toall)
	local settings = getMOOSettings()
	local split = string.Explode(" ", text)
	local params = table.Copy(split)
	table.remove(params, 1)
	params = table.concat(params, " ")
	local n = string.Trim(split[1])
	local sequence = "/"
	if settings["command_sequence"] then
		sequence = settings["command_sequence"]
	end
	if string.sub(n, 1, string.len(sequence)) == sequence then
		n = string.sub(n, 2)
		ply:ConCommand("echo Attempting to run command: " .. n)
		local par = {ply, text, params, toall}
		return executeFunc(n, par)
	else
		for i, textMod in pairs(textModifiers) do
			local ret = textMod(ply, text, toall)
			if ret then
				return ret
			end
		end
		return text
	end
end
hook.Add("PlayerSay", "chatIn", chatIn)